package com.sangeng.ss.utils;

import com.sangeng.ss.service.Process;
import lombok.extern.slf4j.Slf4j;

import java.util.function.Supplier;

/**
 * @author ：xxx
 * @description：TODO
 * @date ：2024/03/19 11:35
 */
@Slf4j
public class ExceptionUtils {


    public static void eatException(Process process){
        try {
            process.execute();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
    }

    public static void eatException(Process process,String message){
        try {
            process.execute();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage()+ message);
        }
    }

    public static <T> T eatException(Supplier<? extends T> supplier, String message){
        try {
            return supplier.get();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage()+ message);
            throw new  RuntimeException(message);
        }
    }

    public static <T> T eatException(Supplier<? extends T> supplier){
        try {
            return supplier.get();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            throw new  RuntimeException(e.getMessage());
        }
    }


}
